import { lib, game, ui, get, ai, _status } from '../../../noname.js';
import { swTool } from "../main/swTool.js";
import { doudizhu } from '../mode/doudizhu.js';
import { identity } from '../mode/identity.js';
import { versus } from '../mode/versus.js';
import { hemengaozhan } from '../mode/hemengaozhan/hemengaozhan.js';
import { langrensha } from '../mode/langrensha/langrensha.js';

//此处的模式和上方导入的模式对应，获取对应的导出对象
const modeSwitch = {
	identity,
	doudizhu,
	versus,
	hemengaozhan,
	langrensha,
};

//一个不知道干嘛的函数。。。
function loadModeConfig(mode) {
	if (typeof modeSwitch[mode] === 'function') {
		modeSwitch[mode]();
	}
}

export let chooseCharacterOL = function () {
	const mode = get.mode();
	const handler = modeSwitch[mode];

	if (handler?.chooseMode) {
		handler.modeConfig?.();
		handler.chooseMode.call(this, arguments);
	}
};
//给联机修改让权限，防止冲突
if (!lib.config[`extension_联机修改_enable`]) {
	//game获取的时候优先获取这里的
	Object.defineProperty(game, 'chooseCharacterOL', {
		configurable: false,
		get: () => chooseCharacterOL,
		set: (v) => {
			const mode = get.mode() || lib.config.mode;
			loadModeConfig(mode);//如果有对应的模式配置，那么优先加载一次，好像目前写的都触发不了这个
			if (mode && !swTool.mode.includes(mode)) { //当且仅当我没有修改过的模式的chooseCharacterOL才允许被修改
				chooseCharacterOL = v;
			}
		}
	});
}

